#include "servicecode/redisserver.h"


Redisserver::Redisserver()
:_redis(redisConnect("127.0.0.1",6379))
{
    if(!_redis){
        LogError("redis连接失败");
        return;
    }
}


bool Redisserver::hsetRedis(const string & key,const string & value)
{
    redisReply* ret = (redisReply*) redisCommand(_redis,"hset search %s %s",key.c_str(),value.c_str());
    if(!ret){
        LogError("redis hset failed");
        return false;
    }

    if(ret->type == REDIS_REPLY_STATUS){
        LogInfo("已将 %d 的搜索结果存入redis",key.c_str());
        return true;
    }else if(ret->type == REDIS_REPLY_ERROR){
        LogError("redis hset failed");
        return false;
    }
}
 

bool Redisserver::hgetRedis(const string & key,string & value)
{
    redisReply* ret = (redisReply*) redisCommand(_redis,"hget search %s",key.c_str());
    if(!ret){
        LogError("redis hset failed");
        return false;
    }
    if(ret->type == REDIS_REPLY_STRING){
        LogInfo("在redis中找到搜索词:%s",key.c_str());
        value = ret->str;
        return true;
    }else{
        LogInfo("在redis中没有找到搜索词:%s");
        return false;
    }
}
 